#include "EventList.h"


EventList::EventList()
{
}


EventList::~EventList()
{
}


GameObject* EventList::ActivateFirst()
{
	if (Empty())
		throw "EventList: Could not activate, list is empty";

	DirectedGameEvent& directedEvent = events.front();


	directedEvent.Activate();

	return directedEvent.Receiver();
}

void EventList::DropFirst()
{
	std::list<DirectedGameEvent>::iterator it = events.begin();


	DirectedGameEvent& directedEvent = *it;

	delete directedEvent.Event();

	events.erase( it );
}

void EventList::Clear()
{
	std::list<DirectedGameEvent>::iterator it;

	for(it = events.begin(); it != events.end(); ++it)
	{
		const DirectedGameEvent& directedEvent = *it;

		delete directedEvent.Event();
	}

	events.clear();
}

void EventList::AddEvent(GameObject* receiver, GameEvent* gameEvent)
{
	events.push_back( DirectedGameEvent(receiver, gameEvent->Clone() ) );
}

bool EventList::Empty() const
{
	return events.size() == 0;
}

